package frontend.pages.admin.shift;

import backend.model.admin.Shift;
import backend.service.admin.ShiftService;
import frontend.core.TimeTrackingWebApplication;
import frontend.model.admin.ShiftUIModel;
import frontend.pages.admin.base.AbstractManagingPage;
import org.apache.wicket.markup.html.panel.Panel;
import org.wicketstuff.annotation.mount.MountPath;

import java.util.List;

@MountPath("shift")
public class ShiftManagingPage extends AbstractManagingPage<Shift> {

	public ShiftManagingPage() {
		super("pages.admin.shift.title", "contextualHelp.admin.shift.text");
	}

    @Override
    protected String getAddPanelTitleKey() {
        return "pages.admin.shift.add.title";
    }

    @Override
    protected String getEditPanelTitleKey() {
        return "pages.admin.shift.edit.title";
    }

    @Override
    protected String getNoSelectionMessageKey() {
        return "pages.admin.shift.edit.noSelection";
    }

    @Override
    protected Panel getAddPanel(String panelId) {
        return new ShiftPanel(panelId, getPageParameters(), new ShiftUIModel());
    }

    @Override
    protected Panel getEditPanel(String panelId, Shift shift) {
        getPageParameters().clearNamed();
        return new ShiftPanel(panelId, null, new ShiftUIModel(shift));
    }

    @Override
    public List<Shift> loadAvailableEntities() {
        ShiftService shiftService = TimeTrackingWebApplication.getService(ShiftService.class);
        return shiftService.findAllShifts();
    }
}
